<?php
/************************************************************************************************
 * Copyright (c) 2004-2008, codesign
 * 
 * All rights reserved.
 * 
 * LICENCE CC/BSD
 * You are free:
 * 
 * to Share & to copy, distribute and transmit the work
 * to Remix & to adapt the work
 * 
 * Under the following conditions:
 * 
 * Attribution. You must attribute the work in the manner specified by the author or 
 * licensor (but not in any way that suggests that they endorse you or your use of the work).
 * Share Alike. If you alter, transform, or build upon this work, you may distribute 
 * the resulting work only under the same, similar or a compatible license.
 * For any reuse or distribution, you must make clear to others the license terms of 
 * this work. The best way to do this is with a link to this web page.
 * Any of the above conditions can be waived if you get permission from the copyright holder.
 * Nothing in this license impairs or restricts the author's moral rights.
 * 
 * LICENCE BSD
 * Redistribution and use in source and binary forms, with or without modification, 
 * are permitted provided that the following conditions are met:
 * 
 * Redistributions of source code must retain the above copyright notice,
 * this list of conditions and the following disclaimer.
 * Redistributions in binary form must reproduce the above copyright notice, 
 * this list of conditions and the following disclaimer in the documentation 
 * and/or other materials provided with the distribution.
 * Neither the name of "codesign" nor the names of its contributors may be used 
 * to endorse or promote products derived from this software without specific prior written permission.
 * 
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 ************************************************************************************************/
if( !defined( 'TEST_FLUID_CSS' ) ): define( 'TEST_FLUID_CSS', 1 );

include_once 'FluidCssParser.class.php5';



if(!function_exists('compressText')):
function compressText( $text )
	{
	return( preg_replace( '([\s]+)', '', $text ) );
	}
endif;



class TestOfFLUID_CSS extends UnitTestCase
	{
	////////////////////////////////////////////////////////////
	function setUp()
		{
		}
	////////////////////////////////////////////////////////////
	function tearDown()
		{
		}
	////////////////////////////////////////////////////////////
	function testEmptyCSS()
		{
		$parser = new FluidCssParser;
		$parser->loadString( '' );
		$parser->parse();
		
		$css = $parser->getCSS();
		
		$this->assertEqual( $css, '' );
		}
	////////////////////////////////////////////////////////////
	function testNotParsedCSS()
		{
		$parser = new FluidCssParser;
		$parser->loadString( 'nothing' );
		$parser->parse();
		
		$css = $parser->getCSS();
		
		$this->assertEqual( $css, 'nothing' );
		}
	////////////////////////////////////////////////////////////
	function testVariableReplace()
		{
		$parser = new FluidCssParser;
		$css =<<<CSS
@brand_color: #000;
@color : #f00;
#header {
	color : @color;
}
h1 {
	background-color : @brand_color;
}
CSS;
		$final_css =<<<CSS
#header {
	color : #f00;
}
h1 {
	background-color : #000;
}
CSS;
		$parser->loadString( $css );
		$parser->parse();
		
		$css = $parser->getCSS();
		
		$this->assertEqual( $css, $final_css );
		}
	////////////////////////////////////////////////////////////
	function testMixins()
		{
		$parser = new FluidCssParser;
		$css =<<<CSS
@brand_color: #000;
.common-rule1 {
	color:@brand_color;
	}
#header {
	width:100px;
	@inc(.common-rule1);
	@inc(.common-rule);
}
h1 {width:100px; @inc(.common-rule1)}
CSS;
		$final_css =<<<CSS
.common-rule1 {
	color:#000;
	}
#header {
	width:100px;
	color:#000;
}
h1 {width:100px; color:#000;}
CSS;
		$parser->loadString( $css );
		$parser->parse();
		
		$css = $parser->getCSS();
		
		$this->assertEqual( compressText($css), compressText($final_css) );
		}
	////////////////////////////////////////////////////////////
	function testIncludeFile()
		{
		$parser = new FluidCssParser;
		$css =<<<CSS
@inc(/ie7.css);
h1 {width:100px;}
CSS;
		$final_css =<<<CSS
.clear, .clearfloat { display:inline-block }
input.sir {text-indent:0;}


/*= ALPHA --------------------------------*/
.alpha10 { filter: alpha(opacity=10); }
.alpha20 { filter: alpha(opacity=20); }
.alpha30 { filter: alpha(opacity=30); }
.alpha40 { filter: alpha(opacity=40); }
.alpha50 { filter: alpha(opacity=50); }
.alpha60 { filter: alpha(opacity=60); }
.alpha70 { filter: alpha(opacity=70); }
.alpha80 { filter: alpha(opacity=80); }
.alpha90 { filter: alpha(opacity=90); }
h1 {width:100px;}
CSS;
		$parser->loadString( $css );
		$parser->parse();
		
		$css = $parser->getCSS();
		
		$this->assertEqual( compressText($css), compressText($final_css) );
		}
	////////////////////////////////////////////////////////////
	function testOperandPlus()
		{
		$parser = new FluidCssParser;
		$css =<<<CSS
@base:10px;
@more:20px;
h1 {
	border:@eval( 0 + @base + 5 + 0 + @more)px;
}
CSS;
		$final_css =<<<CSS
h1 {
	border:35px;
}
CSS;
		$parser->loadString( $css );
		$parser->parse();
		
		$css = $parser->getCSS();
		
		$this->assertEqual( $css, $final_css );
		}
	////////////////////////////////////////////////////////////
	function testOperandComposed()
		{
		$parser = new FluidCssParser;
		$css =<<<CSS
@page_width:834px;
@b_nav_height:18px;
@b_nav_font_size:10px;
@b_nav_padding:4px;
@b_anime_height:253px;
#b-body-wrapper {width:@page_width;height:@eval(@b_nav_height+@b_anime_height)px;position:absolute;top:50%;left:50%;margin:-@eval((@b_nav_height+@b_anime_height)/2)px 0 0 -@eval(@page_width/2)px;}
CSS;
		$final_css =<<<CSS
#b-body-wrapper {width:834px;height:271px;position:absolute;top:50%;left:50%;margin:-135px 0 0 -417px;}
CSS;
		$parser->loadString( $css );
		$parser->parse();
		
		$css = $parser->getCSS();
		
		$this->assertEqual( $css, $final_css );
		}
	}
	
endif;
?>